package cn.yijvyan.bos.mq;

import java.io.UnsupportedEncodingException;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Service;

import cn.yijvyan.bos.utils.SmsUtils;

@Service("smsConsumer")
public class SmsConsumer implements MessageListener{

	@Override
	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage) message;
		try {
			String result = SmsUtils.sendSmsByHTTP(mapMessage.getString
					("telephone"),mapMessage.getString("msg"));
			//		String result = "0001/xxxx";
			if (result.startsWith("000")) {
				System.out.println("发送短信成功,手机号:"+mapMessage.getString("telephone")+
						",验证码:"+mapMessage.getString("msg"));
			} else {
				throw new RuntimeException("短信发送失败,信息码:"+result);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
